﻿@{
    ViewBag.Title = "门诊工作量";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<head>
    <meta charset="utf-8">
    <script src="~/Content/js/echarts.min.js"></script>
    <style>
        .bk {
            border-radius: 10px;
            background-color: white;
        }
        .down_border {
            border-bottom: 1px solid #e6e6e6;
        }
        .ui-jqgrid .ui-jqgrid-bdiv {
            overflow-x: hidden;
        }
    </style>
</head>

<div  class="panel panel-default">
    <table class="form">
        <tr>
            <th class="formTitle" id="xzsjtext">类型：</th>
            <td class="formValue" style="width:150px">
                <select id="dateType" class="form-control" onchange="updateSjType()">
                    <option value="1">年</option>
                    <option value="2">月</option>
                    <option value="3">日</option>
                </select>
            </td>
            <th class="formTitle" id="xzsjtext">时间：</th>
            <td class="formValue" style="width:150px">
                <input id="rSJ" type="text" class="form-control input-wdatepicker" />
            </td>
            <td class="formValue" style="padding-left:20px;">
                <input type="button" id="btn_search" onclick="submit();" class="btn btn-primary btn-md" value="查询" style="width:55px" />
            </td>
        </tr>
    </table>

    <div id="main_div">
        <div style="width:100%;height:48%;background-color:#ffffff;">
            <div class="panel-heading down_border">
                <i class="fa fa-table fa-lg" style="margin-right:5px;"></i>门诊科室工作量
            </div>
            <table id="gridJSListmzksgzl"></table>
        </div>

        <div style="width:100%;margin-top:15px;height:48%;background-color:#ffffff;">
            <div class="panel-heading down_border">
                <i class="fa fa-table fa-lg" style="margin-right:5px;"></i>医生工作量
            </div>
            <table id="gridJSListysgzl"></table>
        </div>
    </div>
</div>
<script>

    var myDate = new Date();
    $(function () {

        $('#main_div').height($(window).height() - 60);
        //默认设置时间类型为月
        $("#dateType").val("2");
        $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy-MM' })");
        $('#rSJ').val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1));
        gridJSListData();
    });

    //根据年月获取月天数
    function getDaysInMonth(year, month) {
        return new Date(year, month, 0).getDate();
    }
    //改变时间类型
    function updateSjType() {
        $('#rSJ').val("");
        let dateType = $("#dateType").val();
        if (dateType == "1") {//年
            $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy' })");
            $('#rSJ').val(myDate.getFullYear());
        }
        if (dateType == "2") {//月
            $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy-MM' })");
            $('#rSJ').val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1));
        }
        if (dateType == "3") {//日
            $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy-MM-dd' })");
            $('#rSJ').val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1) + "-" + myDate.getDate());
        }
    }

    function submit() {
        $("#gridJSListmzksgzl").jqGrid('setGridParam', {
            postData: getSearchData(),
        }).trigger('reloadGrid');
    }
    //组装请求参数
    function getSearchData() {
        let ksrq = '';
        let jsrq = '';
        let dateType = $("#dateType").val();
        let nowDate = $("#rSJ").val();
        if (dateType == "1") {//年
            ksrq = nowDate + "-" + "01-01 00:00:00";
            jsrq = nowDate + "-" + "12-31 23:59:59";
        }
        if (dateType == "2") {//月
            let array = nowDate.split("-");
            ksrq = array[0] + "-" + array[1] + "-01 00:00:00";
            let days = getDaysInMonth(array[0], array[1]);
            jsrq = array[0] + "-" + array[1] + "-" + days + " 23:59:59";
        }
        if (dateType == "3") {//日
            ksrq = nowDate + " 00:00:00";
            jsrq = nowDate + " 23:59:59";
        }
        return { ksrq: ksrq, jsrq: jsrq};
    }
    function getSearchData(ks) {
        let ksrq = '';
        let jsrq = '';
        let dateType = $("#dateType").val();
        let nowDate = $("#rSJ").val();
        if (dateType == "1") {//年
            ksrq = nowDate + "-" + "01-01 00:00:00";
            jsrq = nowDate + "-" + "12-31 23:59:59";
        }
        if (dateType == "2") {//月
            let array = nowDate.split("-");
            ksrq = array[0] + "-" + array[1] + "-01 00:00:00";
            let days = getDaysInMonth(array[0], array[1]);
            jsrq = array[0] + "-" + array[1] + "-" + days + " 23:59:59";
        }
        if (dateType == "3") {//日
            ksrq = nowDate + " 00:00:00";
            jsrq = nowDate + " 23:59:59";
        }
        return { ksrq: ksrq, jsrq: jsrq, ks: ks };
    }
    function gridJSListData()
    {
        var gridSort = 'CreateTime asc';
        var $gridJsList = $("#gridJSListmzksgzl");
        $gridJsList.dataGrid({
            height: 300,
            autowidth: true,//如果shrinkToFit为true且设置了width值，则每列宽度会根据width成比例缩放；
            shrinkToFit: true, //如果设为true，则Grid的宽度会根据父容器的宽度自动重算。**
            url: "/DeanInquiryManage/OutpatientWorkload/GetMzksgzl",
            postData: getSearchData(),
            colModel: [
                { label: '门诊科室', name: 'mzks',  align: 'left' },
                { label: '门诊诊疗人次', name: 'mzzlrc',  align: 'left' },
                { label: '处方数量', name: 'cfsl',  align: 'left' },
                { label: '开药处方数', name: 'kycfs',  align: 'left' },
                { label: '发药处方数', name: 'fycfs',  align: 'left' },
                { label: '康复处方数', name: 'kfcfs', align: 'left' },
                { label: 'DepartmentCode', name: 'DepartmentCode', align: 'left', hidden: true }
            ],
            sortname: gridSort,
            viewrecords: true,
            onSelectRow: function (rowid) {
                var rowObj = $gridJsList.jqGrid('getRowData', rowid);
                console.log("bqCode", rowObj.DeptmentCode)
                var $gridysList = $("#gridJSListysgzl");
                $gridysList.jqGrid('setGridParam', {
                    postData: getSearchData(rowObj.DepartmentCode),
                    url: "/DeanInquiryManage/OutpatientWorkload/GetYsgzl",
                }).trigger('reloadGrid');
            },
            loadComplete: function () {
                var ids = $('#gridJSListmzksgzl').getDataIDs();//返回数据表的ID数组["66","39"..] 
                var rowData = $("#gridJSListmzksgzl").getRowData(ids[0]);
                if (rowData != null) {
                    if (rowData.rowData != "") {
                        YSGZLGrid(rowData.DepartmentCode);
                    }
                }
            }
        });

    }
    function YSGZLGrid(ks) {

        var gridSort = 'CreateTime asc';
        var $gridJsList = $("#gridJSListysgzl");
        $gridJsList.dataGrid({
            height: $(window).height() * 0.5 - 150,
            autowidth: true,//如果shrinkToFit为true且设置了width值，则每列宽度会根据width成比例缩放；
            shrinkToFit: true, //如果设为true，则Grid的宽度会根据父容器的宽度自动重算。**
            url: "/DeanInquiryManage/OutpatientWorkload/GetYsgzl",
            postData:getSearchData(ks),
            colModel: [
                { label: '医生', name: 'Name', align: 'left' },
                { label: '门诊诊疗人次', name: 'mzzlrc', align: 'left' },
                { label: '处方数量', name: 'cfsl', align: 'left' },
                { label: '开药处方数', name: 'kycfs', align: 'left' },
                { label: '发药处方数', name: 'fycfs', align: 'left' },
                { label: '康复处方数', name: 'kfcfs', align: 'left' }
            ],
            sortname: gridSort,
            viewrecords: true
        });

    }
</script>
